package leetcode.L1000;

public class EX861 {

    public static void main(String[] args) {
        int [][] matrix = {{0,0,1,1},{1,0,1,0},{1,1,0,0}};

        //row是行
        //col是列

        int row = matrix.length;
        int col = matrix[0].length;
        double p = col-1;
        int res = 0;

        //把第一列换成1，其他的按照1最多的情况来转换
        for (int i = 0; i <row ; i++) {
            if(matrix[i][0]==0){
                for (int j = 0; j <col ; j++) {
                    if(matrix[i][j] == 0){
                        matrix[i][j]=1;
                    }
                    else {
                        matrix[i][j]=0;
                    }
                }
            }
        }

        for (int i = 0; i < col ; i++,p--) {
            int one = 0;
            int zero = 0;
            for (int j = 0; j < row ; j++) {

                if(matrix[j][i]==0){
                    zero++;
                }
                else {
                    one ++;
                }
            }
            if(zero>one){
                res += (int) (zero*(Math.pow((double) (2),p)));
            }
            else {
                res += (int) (one*(Math.pow((double) (2),p)));
            }
        }
        System.out.println(res);

    }

}
